#ifndef __USR_COMMON_H
#define __USR_COMMON_H
//#include "main.h"
//#include "usr_gnss.h"
// #include "usr_low_power.h"
// #include "usr_audio_play.h"
// #include "lib_in_bsloc.h"
// #include "lib_in_agnss.h"

#define POLYNOMIAL 0xEDB88320

#define PRODUCT_ID "Vehicle Mounted GNSS Localizer"
#define VERSION_4G "0.0.1"
#define VERSION_HARD "1.0"
#define MQTT_HOST    	"gps-lot-258272.hainabaichuang.cn"   				// MQTTS服务器的地址和端口号
#define MQTT_PORT		1883     
#define USERNAME    	"gps_car"                 
#define PASSWORD    	"xifh9j24reg@X3nmO"  
//extern DEV_GNSS_T;
typedef enum
{
    ACC_STATUS = 0,
    BIKE_LOCKED,
    ANTI_THEFT,
    MOVE_FLAG,
    WORK_STATUS,
    POWER_STATUS,
    QRY_STATUS,
    GPS_STATUS,
} EBIKE_STATE_INFO_E;
typedef enum
{    
    EBIKE_STATUS= 0,//车辆状态发生改变
    GNSS_STATUS,//GPS定位状态发生改变，注意是有效定位和无效定位的改变，而不是坐标位置的改变。
    LOW_SOC,//电量由高变低，低于阀值：42V，低电量告警
    WHEEL_STATUS,//异常轮动告警
    NO_CHANGE,//清除已上报的事件，避免重复触发已上报的事件。
} CHANGE_STATE_T;




typedef enum
{
    BSLOC_SUCCESS = 0,
    BSLOC_PROCESS_FAIL,
    BSLOC_UNKNOWN_LOCATION,
    BSLOC_PERMISSION_ERROR,
    BSLOC_UNKNOWN_ERROR,
    BSLOC_RECV_FAIL,
    BSLOC_REQUEST_FAIL,
    BSLOC_CELL_ASYNC_FAIL,
    BSLOC_GET_NOTUFY_CELL_FAIL,
    BSLOC_DNS_FAIL,
}BSLOC_STATE_E;
typedef struct bsloc_t
{
    int latitude;
    int longitude;
    time_t ts;
    BSLOC_STATE_E result;
} BASE_LOC_T;
typedef struct
{
    bool  play_f;
    int play_num;    
} BEEP_PLAY_T;
typedef struct
{
    bool power_f;    
    bool acc_statu;            ///閿燂拷 off, 2: acc on
    bool bike_locked;          /// 1: 
    bool anti_theft;           /// 0: 
    bool qry_status;
    bool move_flag;            /// 
    bool gnss_f;
    uint32_t vin;                 /// 
    int8_t temp;
    uint8_t work_statu;
    uint8_t rules;
    SLEEP_STATE_INFO_T sleep;     /// 
     DEV_GNSS_T gnss;              /// 
     BASE_LOC_T bsloc;             /// 
    luat_rtos_mutex_t mutex;
} EBIKE_STATE_T;

typedef enum
{    
    V_OFF,  // 0 off
    V_ON,   // 1 on
} SWITCH_NUM_E;
typedef enum
{
    V_STOP,   // 0 静止
    V_MOVE,//骑行
    V_SLEEP//低功耗
} WORK_STATU_NUM;
void usr_app_init(void);
char *get_ver_4g(DEV_INFO_T *dev);
char *get_ver_hard(DEV_INFO_T *dev);
time_t get_startup_ts(DEV_INFO_T *dev);
void set_startup_ts(DEV_INFO_T *dev, time_t ts);
time_t get_real_ts(DEV_INFO_T *dev);
void set_real_ts(DEV_INFO_T *dev, time_t ts);
LUAT_PM_POWERON_REASON_E get_startup_reason(DEV_INFO_T *dev);
SWITCH_NUM_E get_ebike_state_info(EBIKE_STATE_T *ebike, EBIKE_STATE_INFO_E ebike_info);
void set_ebike_state_info(EBIKE_STATE_T *ebike, EBIKE_STATE_INFO_E ebike_info, SWITCH_NUM_E state);

uint32_t crc32_compute(const void *data, size_t size, uint32_t poly);
void set_ebike_temp(EBIKE_STATE_T *ebike,uint8_t temp);
uint32_t get_ebike_vin(EBIKE_STATE_T *ebike);

void set_ebike_vin(EBIKE_STATE_T *ebike, uint32_t vin);

int get_reset_reason(void);

#endif /* __USR_COMMON_H */
